package com.mindata.blockchain.core.service;

import com.mindata.blockchain.core.manager.DbBlockManager;
import com.mindata.blockchain.core.manager.PermissionManager;
import com.mindata.blockchain.socket.body.base.ViewChangeBody;
import com.mindata.blockchain.socket.client.PacketSender;
import com.mindata.blockchain.socket.packet.BlockPacket;
import com.mindata.blockchain.socket.packet.PacketBuilder;
import com.mindata.blockchain.socket.packet.PacketType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TestViewChangeService {
    @Resource
    private InstructionService instructionService;
    @Value("${version}")
    private int version;
    @Resource
    private PacketSender packetSender;
    @Resource
    private DbBlockManager dbBlockManager;
    @Resource
    private PermissionManager permissionManager;

    public ViewChangeBody handleViewChangeBody(ViewChangeBody viewChangeBody) {

        /**
         * 1. 实现viewchange消息验证
         * 2. 广播Viewchange消息
         */
        //viewchange消息验证
        // 广播Viewchange消息
        BlockPacket blockPacket = new PacketBuilder<>().setType(PacketType.VIEW_CHANGE).setBody(viewChangeBody).build();
        packetSender.sendGroup(blockPacket);
        return viewChangeBody;
    }
}
